package com.macro.mall.portal.util;

import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Maps;

import java.util.Map;

public class Mapping {
    /**用户身份 01-居民 02-居委会 03-物业公司 04-业委会 05-物管会 06-管理员 07-供应商 08-政府组织 09-其他*/
    public static Map<String,String> userIdentityMap = Maps.newConcurrentMap();
    static {
        userIdentityMap.put("01",	"居民");
        userIdentityMap.put("02",	"居委会");
        userIdentityMap.put("03",	"物业公司");
        userIdentityMap.put("04",	"业委会");
        userIdentityMap.put("05",	"物管会");
        userIdentityMap.put("06",	"管理员");
        userIdentityMap.put("07",	"供应商");
        userIdentityMap.put("08",	"政府组织");
        userIdentityMap.put("09",	"其他");
    }

    public static String getSplitName(String userIdentity){
        if (StrUtil.isEmpty(userIdentity)) {
            return null;
        }
        String[] userIdentityStr = userIdentity.split(",");
        StringBuffer sb = new StringBuffer();
        for (String ui : userIdentityStr) {
            if (!Mapping.userIdentityMap.containsKey(ui)) {
                return null;
            }
            sb.append(Mapping.userIdentityMap.get(ui)).append(",");
        }
        sb.deleteCharAt(sb.length()-1);
        return sb.toString();
    }

    public static String getSplitId(String userIdentityName){
        if (StrUtil.isEmpty(userIdentityName)) {
            return null;
        }
        String[] nameStr = userIdentityName.split(",");
        StringBuffer sb = new StringBuffer();
        for (String uin : nameStr) {
            if (!Mapping.userIdentityMap.containsValue(uin)) {
                return null;
            }
            for (Map.Entry<String, String> m : Mapping.userIdentityMap.entrySet()) {
                if (m.getValue().equals(uin)) {
                    sb.append(m.getKey()).append(",");
                    break;
                }
            }
        }
        sb.deleteCharAt(sb.length()-1);
        return sb.toString();
    }
    public static Map<String,String> valueMap = Maps.newConcurrentMap();
    static {
        valueMap.put("居民","01");
        valueMap.put("居委会","02");
        valueMap.put("物业公司","03");
        valueMap.put("业委会","04");
        valueMap.put("物管会","05");
        valueMap.put("管理员","06");
        valueMap.put("供应商","07");
        valueMap.put("政府组织","08");
        valueMap.put("其他","09");
    }
}
